package com.jiangli.controller.user;


import com.github.pagehelper.Page;
import com.jiangli.annotation.RateLimit;
import com.jiangli.entity.Dish;
import com.jiangli.result.PageResult;
import com.jiangli.result.Result;
import com.jiangli.service.DishService;
import com.jiangli.service.MerchantService;
import com.jiangli.service.Search.DishSearchService;
import com.jiangli.service.Search.IngredientSearchService;
import com.jiangli.service.Search.MerchantSearchService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 菜品搜索控制器
 */
@RestController
@RequestMapping("/user/")
@Slf4j
public class SearchController {

    @Autowired
    private DishSearchService dishSearchService;
    @Autowired
    private MerchantSearchService merchantSearchService;
    @Autowired
    private IngredientSearchService ingredientSearchService;
    /**
     * 菜品搜索接口
     * @param keyword 搜索关键词
     * @param page 页码（默认1）
     * @param size 每页条数（默认10）
     */
    @RateLimit
    @GetMapping("/dish/search")
    @ApiOperation("搜索菜品")
    public Result<PageResult> search(
            @RequestParam String keyword,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        log.info("查询菜品{}",keyword);
        PageResult pageResult = dishSearchService.search(keyword, page, size);

        return Result.success(pageResult);
    }
    @RateLimit
    @GetMapping("/merchant/search")
    @ApiOperation("搜索商家")
    public Result<PageResult> searchMerchant(
            @RequestParam String keyword,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size
    ){
        log.info("查询商家{}",keyword);
        PageResult pageResult = merchantSearchService.search(keyword,page,size);
        return Result.success(pageResult);
    }
    @RateLimit
    @GetMapping("/ingredient/search")
    @ApiOperation("根据材料查询菜品")
    public Result<PageResult> searchIngredient(
            @RequestParam String keyword,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        PageResult pageResult = ingredientSearchService.search(keyword,page,size);
        return Result.success(pageResult);
    }

}
